<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="../include/tag.jsp"%>
<%@ page import="com.party.core.model.system.TargetType" %>

<!DOCTYPE html>
<html lang="zh">
<head>
<title>${activity == null ? '发布' : '编辑'}众筹项目</title>
<%@include file="../include/commonFile.jsp"%>
<link rel="stylesheet" href="${ctx}/css/common/list.css">
<link rel="stylesheet" href="${ctx}/static/uploadCI/upload.css">
<link rel="stylesheet" href="${ctx}/css/ui/activity/publish_form.css">
<style type="text/css">
	.ci-img-list .item{
		width: 150px!important;
		height: 120px!important;
/* 		margin-bottom: 50px; */
		margin-bottom: 10px;
		margin-right: 10px;	
		float: left;
	}
	.ci-img-list .item .img-item{
		position: relative;
		width: 150px!important;
		height: 120px!important;
		margin-bottom: 0px!important;
		background-repeat: no-repeat;
		background-position: center;
		background-size: cover;
		cursor: pointer;
		float: none;
	}
	.ci-img-list .item .text-item{
		width: 148px;
		height: 30px;
		border: 1px solid #efefef;
	}
	.show-img{
		width: 80%;
		height: 560px;
		margin:0 auto;
		background-repeat: no-repeat;
		background-size:cover;
		background-position:center center;
	}
</style>
</head><body>
<!--头部-->
<%@include file="../include/header.jsp"%>
<div class="index-outside">
	<%@include file="../include/sidebar.jsp"%>
	<!--内容-->
	<section>
		<div class="section-main">
			<!-- 正文请写在这里 -->
			<div class="add-form-content">
			<form id="myForm" class="layui-form mt20" method="post" action="${ctx}/activity/activity/save.do">
				<div class="layui-form-item">
					<label class="layui-form-label">活动标题<span class="f-verify-red">*</span></label>
					<div class="layui-input-block">
						<input type="text" name="title" lay-verify="title" autocomplete="off"
							placeholder="活动标题" class="layui-input" value="${activity.title}"
						>
						<input type="hidden" name="id" value="${activity.id}" />
						<input type="hidden" name="isCrowdfunded" value="${activity.isCrowdfunded == null ? 1 : activity.isCrowdfunded}" />
					</div>
				</div>
				<div class="layui-form-item member-div created-div">
					<label class="layui-form-label">所属合作商<span class="f-verify-red">*</span></label>
					<div class="layui-input-inline">
						<input type="hidden" name="member" lay-verify="createBy" class="member-id" value="${createBy.id}" />
						<input type="text" value="${createBy.realname}" class="layui-input  member-name" readonly/>
					</div>
					<a class="layui-btn layui-btn-danger" type="button"
					   onclick="openSelMemberDialog(this,'选择所属合作商','${ctx}/system/member/selectMember.do?isPartner=1','800px','570px')">
						选择
					</a>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">发布者<span class="f-verify-red">*</span></label>
						<div class="layui-input-inline">
							<c:if test="${empty activity.publisher}">
								<input type="text" name="publisher" lay-verify="publisher" autocomplete="off" class="layui-input" value="${sessionScope.newCurrentUser.realname}">
							</c:if>
							<c:if test="${not empty activity.publisher}">
								<input type="text" name="publisher" lay-verify="publisher" autocomplete="off" class="layui-input" value="${activity.publisher}">
							</c:if>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">头像<span class="f-verify-red">*</span></label>
					<div class="cover-content">
						<c:if test="${activity == null || empty activity.publisherLogo}">
							<input type="hidden" name="publisherLogo" id="publisherLogo" lay-verify="publisherLogo" value="${sessionScope.newCurrentUser.logo}" />
							<span id="logo-img" class="round-img" style="background-image:url(${sessionScope.newCurrentUser.logo})"></span>
						</c:if>
						<c:if test="${activity != null && not empty activity.publisherLogo}">
							<input type="hidden" name="publisherLogo" id="publisherLogo" lay-verify="publisherLogo" value="${activity.publisherLogo}" />
							<span id="logo-img" class="round-img" style="background-image:url('${activity.publisherLogo}')"></span>
						</c:if>
						<%--<div class="u-single-upload">--%>
							<%--<input type="file" id="upload_logo_img" class="u-single-file" accept="image/gif,image/png,image/jpg,image/jpeg"> <span class="u-single-upload-icon">+添加头像</span>--%>
						<%--</div>--%>
						<a class="layui-btn layui-btn-danger" id="sel_logo_img">+添加头像</a>
					</div>
				</div>
				<c:if test="${(activity.joinNum == 0 && targetCopartner == null) || (targetCopartner != null)}">
					<div class="layui-form-item member-div">
						<div class="layui-inline">
							<label class="layui-form-label">合伙人</label>
							<div class="layui-input-inline">
								<input type="text" value="${targetCopartner.realname}" class="layui-input member-name" readonly />
							</div>
							<c:if test="${targetCopartner == null || activity.joinNum <= 0}">
								<div class="layui-input-inline">
									<input type="hidden" name="copartnerId" class="member-id" value="${targetCopartner.partnerId}" />
									<button class="layui-btn layui-btn-danger" type="button"
											onclick="openSelMemberDialog(this,'选择合伙人','${ctx}/system/member/selectMember.do?isCopartner=1','800px','570px')">选择</button>
									<button class="layui-btn layui-btn-danger" type="button" onclick="clearInfo(this)">清除</button>
								</div>
							</c:if>
						</div>
					</div>
				</c:if>
				<div class="layui-form-item">
					<label class="layui-form-label">海报<span class="f-verify-red">*</span></label>
					<div class="cover-content">
						<input type="hidden" name="pic" id="pic" lay-verify="pic" value="${activity.pic}" />
						<c:if test="${activity == null || empty activity.pic}">
							<span id="cover-img" class="cover-img" style="background-image:url(${ctx}/image/posterImg.png)"></span>
						</c:if>
						<c:if test="${activity != null && not empty activity.pic}">
							<span id="cover-img" class="cover-img" style="background-image:url('${activity.pic}')"></span>
						</c:if>
						<%--<div class="u-single-upload">--%>
							<%--<input type="file" id="" class="u-single-file" accept="image/gif,image/png,image/jpg,image/jpeg"> <span class="u-single-upload-icon">+添加海报</span>--%>
						<%--</div>--%>
						<a class="layui-btn layui-btn-danger" id="sel_pic_img">+添加海报</a>
						<div class="form-word-aux">建议尺寸：800x450</div>
					</div>
				</div>

				<%--<div class="layui-form-item">
					<label class="layui-form-label">公众号二维码</label>
					<div class="cover-content">
						<input type="hidden" name="publicQrCode" id="publicQrCode" lay-verify="publicQrCode" value="${activity.publicQrCode}" />
						<c:if test="${activity == null || empty activity.publicQrCode}">
							<span id="publicQrCode_img" class="cover-img" style="background-image:url(${ctx}/image/posterImg.png)"></span>
						</c:if>
						<c:if test="${activity != null && not empty activity.publicQrCode}">
							<span id="publicQrCode_img" class="cover-img" style="background-image:url('${activity.publicQrCode}')"></span>
						</c:if>
						<div class="u-single-upload">
							<input type="file" id="upload_publicQrCode_img" class="u-single-file" accept="image/gif,image/png,image/jpg,image/jpeg"> <span class="u-single-upload-icon">+添加海报</span>
						</div>
						<div class="form-word-aux">建议尺寸：800x450</div>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">客服二维码</label>
					<div class="cover-content">
						<input type="hidden" name="serviceQrCode" id="serviceQrCode" lay-verify="serviceQrCode" value="${activity.serviceQrCode}" />
						<c:if test="${activity == null || empty activity.serviceQrCode}">
							<span id="serviceQrCode_img" class="cover-img" style="background-image:url(${ctx}/image/posterImg.png)"></span>
						</c:if>
						<c:if test="${activity != null && not empty activity.serviceQrCode}">
							<span id="serviceQrCode_img" class="cover-img" style="background-image:url('${activity.serviceQrCode}')"></span>
						</c:if>
						<div class="u-single-upload">
							<input type="file" id="upload_serviceQrCode_img" class="u-single-file" accept="image/gif,image/png,image/jpg,image/jpeg"> <span class="u-single-upload-icon">+添加海报</span>
						</div>
						<div class="form-word-aux">建议尺寸：800x450</div>
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">公众号名称</label>
						<div class="layui-input-inline">
							<input type="text" name="publicName" lay-verify="publicName" autocomplete="off" class="layui-input"
								   value="${activity.publicName}"
							>
						</div>
					</div>
				</div>--%>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">报名截止时间<span class="f-verify-red">*</span></label>
						<div class="layui-input-inline">
							<input class="layui-input" name="endDate" lay-verify="endDate" placeholder="报名截止时间" id="endTime" readonly
								value='<fmt:formatDate value="${activity.endTime}" pattern="yyyy-MM-dd HH:mm" />'
							/>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">活动开始时间<span class="f-verify-red">*</span></label>
						<div class="layui-input-inline">
							<input class="layui-input" name="startDate" lay-verify="startDate" placeholder="活动开始时间" id="startTime" readonly
								value='<fmt:formatDate value="${activity.startTime}" pattern="yyyy-MM-dd HH:mm" />'
							/>
						</div>
					</div>
				</div>
<!-- 				<div class="layui-form-item"> -->
<!-- 					<div class="layui-inline"> -->
<!-- 						<label class="layui-form-label">活动类型<span class="f-verify-red">*</span></label> -->
<!-- 						<div class="layui-input-inline"> -->
<!-- 							<select name="activityType" lay-verify="activityType"> -->
<!-- 								<option value="">请选择类型</option> -->
<%-- 								<c:forEach var="type" items="${types}"> --%>
<%-- 									<option value="${type.value}" ${activity.activityType == type.value ? 'selected="selected"' : ""}>${type.label}</option> --%>
<%-- 								</c:forEach> --%>
<!-- 							</select> -->
<!-- 						</div> -->
<!-- 					</div> -->
<!-- 				</div> -->
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">人数上限<span class="f-verify-red">*</span></label>
						<div class="layui-input-inline">
							<input type="text" name="limitNum" lay-verify="limitNum" autocomplete="off" class="layui-input"
								value="${activity.limitNum}"
							>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">活动金额<span class="f-verify-red">*</span></label>
						<div class="layui-input-inline">
							<input type="text" name="price" lay-verify="price" placeholder="￥" class="layui-input" value="${activity.price}" ${activity != null ? ' readonly="readonly"' : ''} />
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">众筹主题</label>
						<div class="layui-input-inline">
							<select name="eventId" id="eventId" lay-verify="eventId" lay-filter="eventId">
								<option value=" ">无事件</option>
								<c:forEach var="event" items="${crowdfundEventList}">
									<option value="${event.id}" ${activity.eventId == event.id ? 'selected="selected"' : ""}>${event.name}</option>
								</c:forEach>
							</select>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">消息提示<span class="f-verify-red">*</span></label>
					<div class="layui-input-block">
						<input type="radio" name="crowdfundHintSwitch" value="0" title="否" ${activity == null || activity.crowdfundHintSwitch == 0 ? 'checked="checked"' : ''}>
						<input type="radio" name="crowdfundHintSwitch" value="1" title="是" ${activity != null && activity.crowdfundHintSwitch == 1 ? 'checked="checked"' : ''}>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">隐藏数据<span class="f-verify-red">*</span></label>
						<div class="layui-input-inline">
							<input type="radio" name="templateStyle" value="0" title="否" ${activity == null || activity.templateStyle == 0 ? 'checked="checked"' : ''}>
							<input type="radio" name="templateStyle" value="1" title="是" ${activity != null && activity.templateStyle == 1 ? 'checked="checked"' : ''}>
						</div>
						<div class="dib">
							<a class="red tip-link" href="javascript:openHiddenShow()"><i class="iconfont icon-piclight"></i>效果展示图</a>
							<p class="gray">说明:在前期众筹数据较少时，适当使用隐藏数据功能，可以避免推广的尴尬，等数据较多时可再调整</p>
						</div>
					</div>
				</div>
				<%@include file="./cityAreaMapNew.jsp" %>
<!-- 				<div class="layui-form-item"> -->
<!-- 					<div class="layui-inline"> -->
<!-- 						<label class="layui-form-label">经度<span class="f-verify-red">*</span></label> -->
<!-- 						<div class="layui-input-inline"> -->
<%-- 							<input class="layui-input" name="lng" lay-verify="lng" value='${activity.lng}'/> --%>
<!-- 						</div> -->
<!-- 					</div> -->
<!-- 				</div> -->
<!-- 				<div class="layui-form-item"> -->
<!-- 					<div class="layui-inline"> -->
<!-- 						<label class="layui-form-label">纬度<span class="f-verify-red">*</span></label> -->
<!-- 						<div class="layui-input-inline"> -->
<%-- 							<input class="layui-input" name="lat" lay-verify="lat" value='${activity.lat}'/> --%>
<!-- 						</div> -->
<!-- 					</div> -->
<!-- 				</div> -->
				<div id="mapDiv" class="layui-form-item" style="display: none;">
					<div class="layui-inline">
						<label class="layui-form-label"></label>
						<div class="layui-input-inline">
							<div id="allmap" style="height: 500px;"></div>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">众筹宣言<span class="f-verify-red">*</span></label>
					<div class="layui-input-block">
						<input type="text" name="crowdDeclaration" lay-verify="crowd_xy" autocomplete="off" placeholder="众筹宣言" class="layui-input" value="${activity.crowdDeclaration}">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">支持宣言<span class="f-verify-red">*</span></label>
					<div class="layui-input-block">
						<input type="text" name="supportDeclaration" lay-verify="support_xy" autocomplete="off" placeholder="支持宣言" class="layui-input" value="${activity.supportDeclaration}">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">联合发起宣言<span class="f-verify-red">*</span></label>
					<div class="layui-input-block">
						<input type="text" name="representDeclaration" lay-verify="represent_xy" autocomplete="off" placeholder="联合发起宣言" class="layui-input" value="${activity.representDeclaration}">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">活动描述</label>
					<div class="layui-input-block">
						<input type="text" name="remarks"  placeholder="活动描述" class="layui-input" value="${activity.remarks}">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">跑马灯图片</label>
					<div class="layui-input-block">
						<input type="hidden" name="picList" id="picList" />
						<div class="ci-img-list" id="img_list">
							<c:forEach var="resource" items="${activity.picList}">
								<div class="item" data-url="${resource.resourceUrl}">
									<div class="img-item" style="background-image: url('${resource.resourceUrl}')">
										<i class="layui-icon del-icon" onclick="delQImg(this, '${resource.id}')">&#x1007;</i>
									</div>
<%-- 									<input class="text-item" type="text" value="${resource.remarks}" placeholder="图片描述" /> --%>
								</div>
							</c:forEach>
						</div>
						<a href="javascript:openUploadCI()" class="layui-btn  layui-btn-danger">+添加图片</a>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">视频</label>
					<div class="layui-input-block">
						<input type="hidden" name="videoList" id="videoList" />
						<div style="margin-bottom: 10px;">
							<textarea class="layui-textarea video-link" style="width: calc(100% - 140px);float: left; margin-right: 10px;resize:none" placeholder="视频链接" id="vide_code">${activity.video.resourceUrl}</textarea>
        					<a href="javascript:openUploadVideo()" class="red">如何添加视频？</a>
                            <div class="cl"></div>
						</div>
						<input type="text"  placeholder="视频描述" class="layui-input video-remarks" value="${activity.video.remarks}" >
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">排序号</label>
						<div class="layui-input-inline">
							<input type="text" name="sort" lay-verify="sort" autocomplete="off" class="layui-input" value="${activity.sort}" >
						</div>
					</div>
				</div>
				<div class="layui-form-item">
						<label class="layui-form-label">活动详情<span class="f-verify-red">*</span></label>
						<div class="layui-input-block">
							<script id="ueditor1" type="text/plain"></script>
							<div style="display: none" id="contentView">${activityDetail.content}</div>
							<input type="hidden" name="content" id="content" lay-verify="content"  data-link-ue="ueditor1"/>
						</div>
				</div>
				<div class="layui-form-item">
						<label class="layui-form-label">报名相关<span class="f-verify-red">*</span></label>
						<div class="layui-input-block">
							<script id="relatedUeditor" type="text/plain"></script>
							<div style="display: none" id="applyRelatedView">${activityDetail.applyRelated}</div>
							<input type="hidden" name="applyRelated" id="applyRelated" lay-verify="applyRelated"  data-link-ue="relatedUeditor"/>
						</div>
				</div>
				<div class="layui-form-item">
						<label class="layui-form-label">参赛标准<span class="f-verify-red">*</span></label>
						<div class="layui-input-block">
							<script id="standardUeditor" type="text/plain"></script>
							<div style="display: none" id="matchStandardView">${activityDetail.matchStandard}</div>
							<input type="hidden" name="matchStandard" id="matchStandard" lay-verify="matchStandard"  data-link-ue="standardUeditor"/>
						</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit lay-filter="*">立即提交</a>
						<a href="${ctx}/activity/activity/zcActivityList.do" class="layui-btn layui-btn-primary">取消</a>
					</div>
				</div>
			</form>
			</div>
		</div>
		<div id="hidden_show_plane" class="pt15"  style="display: none;">
			<div class="dib l" style="width: 50%;">
				<div class="pt10 pb10" style="border-right: 1px solid #7f7f7f;">
					<div class="show-img" style="background-image: url(../../image/activity/hidden_show_before.jpg);"></div>
				</div>
				<p class="mt10 f18 tc">（未隐藏数据前）</p>
			</div>
			<div class="dib l" style="width: 50%;">
				<div class="pt10 pb10">
					<div class="show-img" style="background-image: url(../../image/activity/hidden_show_after.jpg);"></div>
				</div>
				<p class="mt10 f18 tc">（隐藏数据后）</p>
			</div>
		</div>
		<!--底部-->
		<%@include file="../include/footer.jsp"%>
	</section>
</div>

<script type="text/javascript" src="${ctxStatic}/UEditor/ueditor.config.js"></script>
<script type="text/javascript" src="${ctxStatic}/UEditor/ueditor.all.js"></script>
<script type="text/javascript" src="${ctxStatic}/UEditor/myplugin/uploadCI.js"></script>
<script type="text/javascript" src="${ctxStatic}/UEditor/myplugin/uploadVideo.js"></script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" src="${ctxStatic}/UEditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="${ctx}/script/common/form_cache.js"></script>
<script>
	var ue = UE.getEditor('ueditor1');
	var relatedUeditor = UE.getEditor('relatedUeditor');
	var standardUeditor = UE.getEditor('standardUeditor');
    var form,formcache;
    txz.initHeader({
        nav:[{
            name: '众筹项目管理',
            href:'${ctx}/activity/activity/zcActivityList.do',
        },{
            name: '${activity == null ? '发布' : '编辑'}众筹项目',
            curr: true
        }],
        btns:[{
            type:'back'
        }]
    });
	$(function() {
        layui.use([ 'form', 'laydate'], function() {
            form = layui.form, laydate = layui.laydate;

            //自定义验证规则
            form.verify({
                title : function(value) {
                    if (value == "") {
                        return '请填写活动标题';
                    }
                },
                createBy : function (value) {
					if (value == "") {
					    return '请选择所属合作商';
					}
                },
                publisher : function(value) {
                    if (value == "") {
                        return "请填写发布者";
                    }
                },
                publisherLogo : function(value) {
                    if (value == "") {
                        return "请上传发布者头像";
                    }
                },
                pic : function(value) {
                    if (value == "") {
                        return "请上传活动海报";
                    }
                },
                startDate : function(value) {
                    if (value == "") {
                        return "请设置活动开始时间";
                    }
                },
                endDate : function(value) {
                    if (value == "") {
                        return "请设置报名截止时间";
                    }
                    var startDate = $("[name=startDate]").val();
                    var endDate = $("[name=endDate]").val();
                    if (endDate >= startDate) {
                        return "报名截止时间应该早于活动开始时间";
                    }
                },
                place : function(value) {
                    if (value == "") {
                        return "请设置活动场所";
                    }
                },
                area : function(value) {
                    if (value == "") {
                        return "请设置活动区域";
                    }
                },
// 			lng : function(value){
// 				if(value == ""){
// 					return "请填写经度"
// 				}
// 			},
// 			lat : function(value){
// 				if(value == ""){
// 					return "请填写纬度"
// 				}
// 			},
                city : function(value) {
                    if (value == "") {
                        return "请选择活动举办的城市";
                    }
                },
                limitNum : function(value) {
                    if (value == "") {
                        return "请设置活动人数上限";
                    } else if (!util.checkNumber(value)) {
                        return "请输入正确的数字";
                    } else if (parseInt(value) == 0) {
                        return "请输入大于0的数字";
                    }
                },
                price : function(value) {
                    if(value == "") {
                        return "请设置活动报名金额";
                    }else if(!util.checkFloat(value)){
                        return "请输入正确的金额";
                    }else if(parseFloat(value) == 0){
                        return "请输入大于0的金额";
                    }
                },
                sort : function(value) {
                    if(!util.checkNumber(value)){
                        return "请输入正确的数字";
                    }
                },
                content : function(value) {
                    $("#contentView").html(ue.getContent());
                    var content = $("#contentView").html();
                    if (content == "") {
                        return "请填写活动详情";
                    }
                },
                matchStandard : function (value) {
                    $("#matchStandardView").html(standardUeditor.getContent());
                    var content = $("#matchStandardView").html();
                    if (content == "") {
                        return "请填写参赛标准";
                    }
                },
                applyRelated : function (value) {
                    $("#applyRelatedView").html(relatedUeditor.getContent());
                    var content = $("#applyRelatedView").html();
                    if (content == "") {
                        return "请填写报名相关";
                    }
                }
            });

            //监听提交
            form.on('submit', function(data) {
                $(data.elem).removeAttr("lay-submit");
                var formData = getFormData();
                var action = $("#myForm").attr("action");
                txz.ajaxRequest({
                    method: 'post',
                    url: action,
                    saveCache: true,
                    cacheObj: formcache,
                    params: formData,
                    callBack: function (res) {
                        if (res.success) {
                            util.layerMsgSuccess("提交成功", function () {
                                txz.saveStatus = true;
                                location.href = "${ctx}/activity/activity/zcActivityList.do";
                            });
                        } else {
                            console.log(res);
                            $(data.elem).attr("lay-submit","");
                            util.layerMsgError("提交失败")
                        }
                    }
                });
                return false;
            });

            //日期
            var start = {
                elem: '#startTime',
                min : '2015-01-01 00:00:00',
                max : '2099-06-16 23:59',
                type: 'datetime',
                format : 'yyyy-MM-dd HH:mm'
            };

            var end = {
                elem: '#endTime',
                min : '2015-01-01 00:00:00',
                max : '2099-06-16 23:59',
                type: 'datetime',
                format : 'yyyy-MM-dd HH:mm' //日期格式
            };
            laydate.render(start);
            laydate.render(end);

            //初始化地图控件
            txz.Map.init({
                layForm: form,
                data: {
                    cityId: '${activity.cityId}',
                    areaInput: '${activity.area}',
                    place: '${activity.place}',
                    cityName: '${cityName}',
                    lat: '${activity.lat}',
                    lng: '${activity.lng}'
                }
            });
            txz.saveStatus = false;
        });
		ue.addListener('ready', function() {
            this.setHeight(500);
			if($("#contentView").html() != ""){
				this.setHeight(850);
			}
			this.setContent($("#contentView").html());
            //等待ueditor加载完后加载缓存
			if(!'${activity.id}') {
                formcache = new fCache({
                    fCacheKey: 'form_cache_zcact',//暂存的key
                    cacheCallback: loadCacheData,//获取到缓存后加载的方法
                    getFormData: getFormData
                }).init();
            }
		});
		ue.addListener('blur', function() {
			$("#contentView").html(ue.getContent());
		});

		relatedUeditor.addListener('ready', function() {
			this.setContent($("#applyRelatedView").html());
            this.setHeight(500);
		});
		relatedUeditor.addListener('blur', function() {
			$("#applyRelatedView").html(ue.getContent());
		});

		standardUeditor.addListener('ready', function() {
			this.setContent($("#matchStandardView").html());
            this.setHeight(500);
		});
		standardUeditor.addListener('blur', function() {
			$("#matchStandardView").html(ue.getContent());
		});

        $('#sel_logo_img').click(function () {
            txz.openSelImg({
                min: 1,
                max: 1,
                type: '<%=TargetType.ZC_ACTIVITY.getCode()%>',
                cb: function (imgs) {


                    $('#logo-img').css('background-image', 'url(' + imgs[0].path + ')');
                    $('#publisherLogo').val(imgs[0].path);
                }
            })
        })
        $('#sel_pic_img').click(function () {
            txz.openSelImg({
                min: 1,
                max: 1,
                info: '建议尺寸：800x450',
                type: '<%=TargetType.ZC_ACTIVITY.getCode()%>',
                cb: function (imgs) {
                    $('#cover-img').css('background-image', 'url(' + imgs[0].path + ')');
                    $('#pic').val(imgs[0].path);
                }
            })
        })
	})
    //此方法用于加载缓存数据
    function loadCacheData(cacheData) {
        //跑马灯
        if(cacheData['picList']){
            var picList = JSON.parse(cacheData['picList']);
            if(picList && picList.length > 0) {
                $("#img_list").html('');
                for (var i = 0, item; i < picList.length; i++) {
                    item = picList[i];
                    $("#img_list").append('<div class="item" data-url="' + item.pic + '">' +
                        '<div class="img-item" style="background-image: url(' + item.pic + ')">' +
                        '<i class="layui-icon del-icon" onclick="delQImg(this, \'\')">&#x1007;</i>' +
                        '</div>' +
                        //'<input class="text-item" type="text" placeholder="图片描述" />'+
                        '</div>');
                }
            }
        }
        //加载视频数据
        if(cacheData['videoList']){
            var video = JSON.parse(cacheData['videoList']);
            $('.video-link').val(video.pic);
            $('.video-remarks').val(video.remarks);
        }
        //加载头像
        if(cacheData['publisherLogo']) {
            $('#logo-img').css('background-image','url('+cacheData['publisherLogo']+')');
        }
        //加载封面图
        if(cacheData['pic']){
            $('#cover-img').css('background-image','url('+cacheData['pic']+')');
        }
        if (cacheData['publicQrCode']){
			$('#publicQrCode_img').css('background-image','url('+cacheData['publicQrCode']+')');
		}
		if (cacheData['serviceQrCode']){
			$('#serviceQrCode_img').css('background-image','url('+cacheData['serviceQrCode']+')');
		}
        form.render();
        txz.Map.init({
            layForm: form,
            data: {
                cityId: cacheData.cityId,
                areaInput: cacheData.areaSelect || cacheData.areaInput,
                place: cacheData.place,
                lat: cacheData.lat,
                lng: cacheData.lng
            }
        });
    }
    function getFormData() {
        $("#content").val(ue.getContent().replace(/&quot;/gi, ""));
        $("#applyRelated").val(relatedUeditor.getContent().replace(/&quot;/gi, ""));
        $("#matchStandard").val(standardUeditor.getContent().replace(/&quot;/gi, ""));
        // 跑马灯
        var length = $("#img_list .img-item").length;
        if(length > 5){
            util.layerMsgError("最多只允许上传5张图片")
            return false;
        }
        var array = new Array();
        $("#img_list .item").each(function(index, element){
            var pic = {
                pic : $(element).attr("data-url"),
                remarks : $(element).find(".text-item").val() || ''
            }
            array.push(pic);
        });
        $("#picList").val(JSON.stringify(array));
        // 视频
        var video = {
            pic : $(".video-link").val(),
            remarks : $(".video-remarks").val()
        }
        $("#videoList").val(JSON.stringify(video));

        return util.serializeForm($('#myForm').serializeArray());
    }
	// 文本编辑器图片上传
	function uEditorUploadCI(editor) {
        txz.openSelImg({
            min: 1,
            type: '<%=TargetType.ZC_ACTIVITY.getCode()%>',
            cb: function (imgs) {
                if (imgs.length) {
                    for (var i = 0, item; i < imgs.length; i++) {
                        item = imgs[i];
                        editor.focus();
                        editor.execCommand('inserthtml', item.htmlStr);
                    }
                }
            }
        })
	}

    function uEditorUploadCIVideo(editor) {
        txz.openSelVideo({
            min: 1,
            type: '<%=TargetType.ZC_ACTIVITY.getCode()%>',
            cb: function (imgs) {
                if (imgs.length) {
                    for (var i = 0, item; i < imgs.length; i++) {
                        item = imgs[i];
                        editor.focus();
                        editor.execCommand('inserthtml', item.htmlStr);
                    }
                }
            }
        })
    }
	
	function openUploadCI() {
        txz.openSelImg({
            min: 1,
			max: 5,
            type: '<%=TargetType.ZC_ACTIVITY.getCode()%>',
            cb: function (imgs) {
                if (imgs.length) {
                    for (var i = 0, item; i < imgs.length; i++) {
                        var item = imgs[i];
                        $("#img_list").append('<div class="item" data-url="'+ item.path +'">'+
                            '<div class="img-item" style="background-image: url('+ item.path +')">'+
                            '<i class="layui-icon del-icon" onclick="delQImg(this, \'\')">&#x1007;</i>'+
                            '</div>'+
                            // 									'<input class="text-item" type="text" placeholder="图片描述" />'+
                            '</div>');
                    }
                }
            }
        })
	}

	function delQImg(obj, resourceId) {
        if(resourceId == null || resourceId == ''){
            $(obj).closest(".item").remove();
        }else{
            $.ajax({
                type : 'post',
                url : '${ctx}/activity/activity/delZcActivityPic.do',
                data : {
                	resourceId : resourceId
                },
                dataType : 'json',
                context : $('body'),
                success : function(data) {
                    $(obj).closest(".item").remove();
                },
                error : function(xhr, type) {
                    console.err('err', 'ajax错误', xhr, type);
                }
            })
        }
	}
	
	function openUploadVideo(){
		var opts = {
			type : 2,
            area : [ '600px', '480px' ],
			title : '添加视频',
			content : '${ctx}/page/upload/myvideo.html',
			btn : [ '确定', '关闭' ],
			yes : function(index, layero) {
				var body = top.layer.getChildFrame('body', index);
				var iframeWin = layero.find('iframe')[0];
				if (iframeWin.contentWindow.doSubmit()) {
					var video = $(iframeWin.contentWindow.$.find("#video_code")).val();
					$("#vide_code").val(video);
					setTimeout(function() {
						top.layer.close(index);
					}, 100);//延时0.1秒，对应360 7.1版本bug
				}
			},
			cancel : function(index) {
			}
		};
		layer.open(opts);
	}

	function openHiddenShow(){
		var index = layer.open({
			type:1,
			area:['800px','700px'],
			title:['手机效果展示图','text-align:center;'],
			shade:0.6,
			shadeClose:true,
			content:$("#hidden_show_plane")
		});
	}

	function clearInfo(that) {
        var $memberDiv = $(that).closest(".member-div");
        $memberDiv.find(".member-id").val("");
        $memberDiv.find(".member-name").val("");
    }

    function openSelMemberDialog(that, title, url, width, height) {
		txz.openDialogIframe({
			width: width,
			height: height,
			title: title,
			url: url,
			cb: function (opt) {
			    var contentWindow = opt.content;
                if (contentWindow.doSubmit()) {
                    var memberId = $(contentWindow.$.find("#memberId")).val();
                    var memberName = $(contentWindow.$.find("#memberName")).val();
                    var logo = $(contentWindow.$.find("#logo")).val();

                    var $memberDiv = $(that).closest(".member-div");
                    $memberDiv.find(".member-id").val(memberId);
                    $memberDiv.find(".member-name").val(memberName);

                    if($memberDiv.hasClass("created-div")) {
                        $("[name=publisher]").val(memberName);
                        $("[name=publisherLogo]").val(logo);
                        $('#logo-img').css('background-image', 'url(' + logo + ')');
                    }
                    setTimeout(function() {
                        top.layer.close(opt.index);
                    }, 100);//延时0.1秒，对应360 7.1版本bug
                }
            }
		})
    }
</script>
</body>
</html>